﻿namespace Neovolve.Extensibility.ReSharper
{
    using System;
    using JetBrains.ProjectModel;
    using JetBrains.ReSharper.Daemon;
    using JetBrains.ReSharper.Daemon.CSharp.Stages;

    /// <summary>
    /// The <see cref="ConvertTypeStage"/>
    ///   class is used to define a daemon stage process.
    /// </summary>
    [DaemonStage(StagesBefore = new[]
                                {
                                    typeof(TypeMemberErrorStage)
                                }, StagesAfter = new[]
                                                 {
                                                     typeof(LanguageSpecificDaemonStage)
                                                 })]
    [CLSCompliant(false)]
    public class ConvertTypeStage : CSharpDaemonStageBase
    {
        /// <summary>
        /// Creates a code analysis process corresponding to this stage for analysing a file.
        /// </summary>
        /// <param name="process">
        /// The daemon process.
        /// </param>
        /// <param name="processKind">
        /// The process kind.
        /// </param>
        /// <returns>
        /// Code analysis process to be executed or <c>null</c> if this stage is not available for this file.
        /// </returns>
        public override IDaemonStageProcess CreateProcess(IDaemonProcess process, DaemonProcessKind processKind)
        {
            if (process == null)
            {
                throw new ArgumentNullException("process");
            }

            if (IsSupported(process.ProjectFile) == false)
            {
                return null;
            }

            return new ConvertTypeStageProcess(process);
        }

        /// <summary>
        /// Check the error stripe indicator necessity for this stage after processing given <paramref name="projectFile"/>.
        /// </summary>
        /// <param name="projectFile">
        /// The project file.
        /// </param>
        /// <returns>
        /// An <see cref="ErrorStripeRequest"/> value.
        /// </returns>
        public override ErrorStripeRequest NeedsErrorStripe(IProjectFile projectFile)
        {
            if (IsSupported(projectFile) == false)
            {
                return ErrorStripeRequest.NONE;
            }

            return ErrorStripeRequest.STRIPE_AND_ERRORS;
        }
    }
}